package com.lovo.test.ATM;

import com.lovo.test.Util.Util;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

//菜单界面
public class MenuPanel extends JPanel implements ActionListener{
    //以下是图片封装
    private Icon storeImg = Util.getIcon("/ATMimages/buttonSave.jpg");//存钱按键
    private Icon takeImg = Util.getIcon("/ATMimages/buttonGet.jpg");//取钱按键
    private Icon checkImg = Util.getIcon("/ATMimages/buttonFind.jpg");//查询按键
    private Icon returnImg = Util.getIcon("/ATMimages/buttonOff.jpg");//返回按键




    private JButton returnBut;//返回按钮
    private JButton takeBut;//取款按钮进入取款界面
    private JButton storeBut;//存款按钮进入存款界面
    private JButton checkBut;//查询按钮进入查询界面
    private JButton turnBut;//转账按钮进入转账界面
    private JButton correctBut;//改密按钮
    private ATM frame;



   public  MenuPanel(ATM frame){
        this.frame=frame;
       //空布局
       this.setLayout(null);
       //设置透明
       this.setOpaque(false);

       //存钱按钮进入存钱界面
       storeBut = new JButton(storeImg);
       storeBut.setBounds(0,100,140,50);
       this.add(storeBut);
       storeBut.addActionListener(this);

       //取钱按钮进入取钱界面
       takeBut = new JButton(takeImg);
       takeBut.setBounds(0,200,140,50);
       this.add(takeBut);
       takeBut.addActionListener(this);

       //查询按钮进入查询界面
       checkBut = new JButton(checkImg);
       checkBut.setBounds(0,300,140,50);
       this.add(checkBut);
       checkBut.addActionListener(this);

       //转账按钮
       turnBut = new JButton("转账");
       turnBut.setBounds(660,100,140,50);
       this.add(turnBut);
       turnBut.addActionListener(this);

       //改密按钮
       correctBut = new JButton("修改密码");
       correctBut.setBounds(660,200,140,50);
       this.add(correctBut);
       correctBut.addActionListener(this);


       //返回按钮返回登陆界面
       returnBut = new JButton(returnImg);
       returnBut.setBounds(660,300,140,50);
       this.add(returnBut);
       returnBut.addActionListener(this);

   }


   //关联方法
    @Override
    public void actionPerformed(ActionEvent e) {
       if (e.getSource()==returnBut){
           frame.switchPanel("登录");//返回到登录界面
       }else if (e.getSource()==takeBut){
           frame.switchPanel("取款");//跳转到取款界面
       }else if (e.getSource()==storeBut){
           frame.switchPanel("存款");//跳转到存款界面
       }else if (e.getSource()==checkBut){
           frame.switchPanel("查询");//跳转到查询界面
           frame.setUserName(AtmMysq.getById(frame.getUserName().getId()));
           frame.getCheckPanel().getUserLabel().setText("当前账户："+frame.getUserName().getUserName());
           frame.getCheckPanel().getPwdLabel().setText("当前余额："+frame.getUserName().getMoney());
       }else if (e.getSource()==turnBut){
           frame.switchPanel("转账");//跳转到转账界面
       }else if(e.getSource()==correctBut){
           frame.switchPanel("改密");
       }

    }
}
